#ifndef HANDLEJSON_H
#define HANDLEJSON_H

#include "define.h"
#include <QJsonObject>
#include <QtSql/QSqlDatabase>
#include <QTcpSocket>
#include <memory>
#include <QJsonParseError>
#include <QtSql/QSqlQuery>
#include <QMessageBox>
#include <QtSql/QSqlError>
#include <QTime>
#include <QRandomGenerator>
#include <QJsonArray>
#include <QTimer>
#include <QObject>
#include <QCoreApplication>

static QSqlDatabase db;

class InitDatabase
{
public:
    static QSqlDatabase& GetInstance();
private:
};

class HandleJson
{
public:
    HandleJson();
    virtual void Handle(const QJsonObject& jsonObj,QTcpSocket* socket) = 0;
public slots:
    void GetAllQuestion(QTcpSocket* socket);  // 获取所有题目
protected:
    QSqlDatabase db;
};

// 宏定义
#define RegisterClass(Name) \
class Name:public HandleJson \
{ \
public: \
    using HandleJson::HandleJson; \
    void Handle(const QJsonObject & jsonObj,QTcpSocket *socket)override; \
};

RegisterClass(Login)        // 注册
RegisterClass(Regis)        // 登录

using HandleJsonPtr = std::shared_ptr<HandleJson>;
HandleJsonPtr GetHandlePtr(const int &type);

#endif // HANDLEJSON_H
